package examples
{
	import com.dreamana.components.Button;
	import com.dreamana.components.Label;
	import com.dreamana.components.Panel;
	import com.dreamana.components.TextInput;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class FirstExample extends Sprite
	{
		public function FirstExample()
		{
			stage? init() : this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(event:Event=null):void
		{
			if(event) this.removeEventListener(event.type, init);
			
			/* First example */
			
			var panel:Panel = new Panel(300, 160);
			panel.setPosition(10, 10);
			this.addChild(panel);
			
			panel.addChild(new Label(64, 20, null, "Username: ", 16, 18));
			panel.addChild(new Label(64, 20, null, "Password: ", 16, 58));
			
			var inputUsername:TextInput = new TextInput(128, 24);
			inputUsername.setPadding(2);
			inputUsername.setTextFieldProps({restrict:"a-zA-Z0-9", maxChars: 24});
			inputUsername.setPosition(96, 16);
			panel.addChild(inputUsername);
			
			var inputPassword:TextInput = new TextInput(128, 24);
			inputPassword.setPadding(2);
			inputPassword.setTextFieldProps({displayAsPassword: true, maxChars: 24});
			inputPassword.setPosition(96, 56);
			panel.addChild(inputPassword);
			
			var button:Button = new Button(128, 24, new Label(128, 20, null, "Login", 0, 2));
			button.setPosition(96, 96);
			panel.addChild(button);
			
			var output:Label = new Label(320, 24, null, "", panel.x, panel.y + panel.height + 10);
			this.addChild(output);
			
			var onClick:Function = function onClick(event:MouseEvent):void
			{
				if(!inputUsername.text) {
					output.text = 'Please enter your username.';
				}
				else if(!inputPassword.text) {
					output.text = 'Please enter your password.';
				}
				else {
					output.text = 'Your input is: ' + '{"username":"' + inputUsername.text + '","password":"'+ inputPassword.text + '"}';
				}
			};
			button.addEventListener(MouseEvent.CLICK, onClick);
		}
	}
}